package com.oms.module.merchant.domain.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.oms.constant.FlagTypeEnum;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @Author zhanghailong QQ38592077
 * @Description TODO
 * @Date 2020/7/7 11:10
 */
@TableName("oms_user")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserEntity implements UserDetails {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String username;
    private String password;
    private String qq;
    private String invitationCode;
    private int invitationCodeType;
    private LocalDateTime createDate;
    private LocalDateTime updateDate;

    /**
     * 账号是否没过期
     */
    private boolean accountNonExpired;
    /**
     * 账号是否没锁定
     */
    private boolean accountNonLocked;
    /**
     * 密码是否没过期
     */
    private boolean credentialsNonExpired;
    /**
     * 禁止登陆
     */
    private boolean enabled;

    private String userFace;
    private String bankName;
    private Long cardNo;
    private String accountName;
    @TableLogic
    private FlagTypeEnum del;
    private int receiptInterval;
    private BigDecimal additionalCost;
    private BigDecimal accountAmount;
    @TableField(exist = false)
    private String shopName;
    @TableField(exist = false)
    private String shopId;


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<SimpleGrantedAuthority> list = new ArrayList<>();
        list.add(new SimpleGrantedAuthority("ROLE_user"));
        return list;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
